package com.cy.controller;

import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cy.common.vo.JsonResult;
import com.cy.entity.SysSpecs;
import com.cy.service.SysGoodsInfoService;

@RestController
@RequestMapping("/GoodsInfo/")
public class SysGoodsInfoController {
	@Autowired
	SysGoodsInfoService sysGoodsInfoService;

	@RequestMapping("getGoodsInfo")
	public JsonResult getGoodsInfo(Integer id) {
		return new JsonResult(sysGoodsInfoService.getGoodsInfo(id));
	}

	@RequestMapping("getGoodsPics")
	public JsonResult getGoodsPics(Integer id) {
		return new JsonResult(sysGoodsInfoService.getGoodsPic(id));
	}

	@RequestMapping("getGoodsBrand")
	public JsonResult getGoodsBrand(Integer id) {
		return new JsonResult(sysGoodsInfoService.getGoodsBrand(id));
	}

	@RequestMapping("getGoodsSpecs")
	public JsonResult getGoodsSpecs(Integer id) {

		List<SysSpecs> specs = sysGoodsInfoService.getGoodsSpecs(id);
		List<List<SysSpecs>> result = new ArrayList<>();
		for (int i = 0; i < specs.size(); i++) {
			List<SysSpecs> item = new ArrayList<>();
			item.add(specs.get(i));
			int Propid = specs.get(i).getProp_id();
			for (int j = i + 1; j < specs.size(); j++) {
				if(specs.get(j).getProp_id() == Propid) {
					item.add(specs.get(j));
					specs.remove(j);
					j--;
				}
			}
			result.add(item);
		}		
		return new JsonResult(result);
	}

}
